//
// Created by Tony on 2024/7/6.
//

#include "LOAD_K.h"
#include "../rt_code/Class.h"

namespace Runtime {

void LOAD_K::execute(RtData::Frame& frame) {
    auto& method = frame.getMethod();
    shared_ptr<RtCode::Class> clazz = method->getOwnerClass();
    auto& constantPool = clazz->getConstantPool();

    auto value = constantPool.getConstant(mIndex);
    switch (value.tag) {
        case RtCode::ConstantTag::INT64:
            return frame.pushValue(RtTaggedValue(value.value.int64));
        case RtCode::ConstantTag::FLT64:
            return frame.pushValue(RtTaggedValue(value.value.flt64));
        default:
            // TODO
            return;
    }
}

} // namespace Runtime
